package com.hjm.project.bankExpenditure.gbTradeInfoTemp.controller;

import java.util.List;
import java.util.Map;

import com.hjm.common.utils.security.ShiroUtils;
import com.hjm.project.bankExpenditure.gbTradeInfoTemp.domain.*;
import com.hjm.project.terminal.manufacturer.service.IManufacturerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.bankExpenditure.gbTradeInfoTemp.service.IGbTradeInfoTempService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 临时交易Controller
 * 
 * @author maker-platform
 * @date 2024-03-11
 */
@Controller
@RequestMapping("/bankExpenditure/gbTradeInfoTemp")
public class GbTradeInfoTempController extends BaseController {
    private String prefix = "bankExpenditure/gbTradeInfoTemp";

    @Resource
    private IGbTradeInfoTempService gbTradeInfoTempService;
    @Resource
    private IManufacturerService manufacturerService;
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:view")
    @GetMapping()
    public String gbTradeInfoTemp(ModelMap mmap) throws Exception {
        List<Map> manufacturer = manufacturerService.getManufacturer(ShiroUtils.isAgent() ? ShiroUtils.getLoginAgentNum() : null);
        mmap.put("manufacturer",manufacturer);
        return prefix + "/gbTradeInfoTemp";
    }

    /**
     * 查询临时交易列表
     */
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GbTradeInfoTemp gbTradeInfoTemp) {
        Map data = gbTradeInfoTempService.selectGbTradeInfoListCount(gbTradeInfoTemp);
        startPage();
        List<GbTradeInfoTemp> list = gbTradeInfoTempService.selectGbTradeInfoTempList(gbTradeInfoTemp);
        return getDataTable(list,data);
    }

    /**
     * 导出临时交易列表
     */
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:export")
    @Log(title = "临时交易", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GbTradeInfoTemp gbTradeInfoTemp) {
        List<GbTradeInfoTemp> list = gbTradeInfoTempService.selectGbTradeInfoTempList(gbTradeInfoTemp);
        ExcelUtil<GbTradeInfoTemp> util = new ExcelUtil<GbTradeInfoTemp>(GbTradeInfoTemp.class);
        return util.exportExcel(list, "gbTradeInfoTemp");
    }

    /**
     * 新增临时交易
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存临时交易
     */
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:add")
    @Log(title = "临时交易", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GbTradeInfoTemp gbTradeInfoTemp) {
        return toAjax(gbTradeInfoTempService.insertGbTradeInfoTemp(gbTradeInfoTemp));
    }

    /**
     * 修改临时交易
     */
    @GetMapping("/edit/{agentno}")
    public String edit(@PathVariable("agentno") String agentno, ModelMap mmap) {
        GbTradeInfoTemp gbTradeInfoTemp = gbTradeInfoTempService.selectGbTradeInfoTempById(agentno);
        mmap.put("gbTradeInfoTemp", gbTradeInfoTemp);
        return prefix + "/edit";
    }

    /**
     * 修改保存临时交易
     */
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:edit")
    @Log(title = "临时交易", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GbTradeInfoTemp gbTradeInfoTemp) {
        return toAjax(gbTradeInfoTempService.updateGbTradeInfoTemp(gbTradeInfoTemp));
    }

    /**
     * 删除临时交易
     */
    @RequiresPermissions("bankExpenditure:gbTradeInfoTemp:remove")
    @Log(title = "临时交易", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(gbTradeInfoTempService.deleteGbTradeInfoTempByIds(ids));
    }


    /**
     * 导出临时交易列表
     */
    @Log(title = "交易对账", businessType = BusinessType.EXPORT)
    @PostMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate(MultipartFile file, Integer tradeType) throws Exception {
        if (tradeType == 2) {
            gbTradeInfoTempService.importTemplate(file, tradeType);
        } else if (tradeType == 5){
            ExcelUtil<GbTradeInfoHdbTemp> util = new ExcelUtil<GbTradeInfoHdbTemp>(GbTradeInfoHdbTemp.class);
            List<GbTradeInfoHdbTemp> userList = util.importExcel(file.getInputStream());
            gbTradeInfoTempService.importTemplateHdb(userList, tradeType);
        } else if (tradeType == 4){
            ExcelUtil<GbTradeInfoZfTemp> util = new ExcelUtil<GbTradeInfoZfTemp>(GbTradeInfoZfTemp.class);
            List<GbTradeInfoZfTemp> userList = util.importExcel(file.getInputStream());
            gbTradeInfoTempService.importTemplateZf(userList, tradeType);
        } else if (tradeType == 1){
            ExcelUtil<GbTradeInfoLsTemp> util = new ExcelUtil<GbTradeInfoLsTemp>(GbTradeInfoLsTemp.class);
            List<GbTradeInfoLsTemp> userList = util.importExcel(file.getInputStream());
            gbTradeInfoTempService.importTemplateLs(userList, tradeType);
        } else if (tradeType == 3){
            ExcelUtil<GbTradeInfoQcfTemp> util = new ExcelUtil<GbTradeInfoQcfTemp>(GbTradeInfoQcfTemp.class);
            List<GbTradeInfoQcfTemp> userList = util.importExcel(file.getInputStream());
            gbTradeInfoTempService.importTemplateQcf(userList, tradeType);
        }
        return AjaxResult.success("任务处理中,请稍后进行查询");
    }

}
